const path = require('path');

const CompressionWebpackPlugin = require('compression-webpack-plugin');

const productionGzipExtensions = ['js', 'css'];

function resolve(dir) {
  return path.join(__dirname, dir);
}
const name = '松鼠互娱'; // 标题
const plugins = [];

if (process.env.NODE_ENV === 'production') {
  plugins.push(
    new CompressionWebpackPlugin({
      algorithm: 'gzip',
      test: new RegExp(`\\.(${productionGzipExtensions.join('|')})$`),
      threshold: 10240,
      minRatio: 0.8,
    }),
  );
}
module.exports = {
  publicPath: process.env.VUE_APP_ENV === 'production' ? 'https://static.009bar.com/hmbarh5-qn/' : '/',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV === 'development',
  productionSourceMap: false,
  devServer: {
    host: '0.0.0.0',
    port: 80,
    open: false,
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: 'https://shm.009bar.com/',
        changeOrigin: true,
        pathRewrite: {
          [`^${process.env.VUE_APP_BASE_API}`]: '',
        },
      },
    },
    disableHostCheck: true,
  },
  configureWebpack: {
    name,
    resolve: {
      alias: {
        '@': resolve('src'),
      },
    },
    plugins,
  },
};
